<template>
  <div class="user">
    <!--在模板里面获取id-->
    <h2> user: {{ $route.params }} </h2>
    <h2> user: {{ $route.params.id }} </h2>
  </div>
</template>

<script setup>
  // 在代码里获取id
  // 没有setup，直接用this.$route.params.id
  // setup里用 route
  import { useRoute, onBeforeRouteUpdate } from 'vue-router'
  import { onActivated } from "vue";
  const route = useRoute()
  console.log(route.params.id)
  onBeforeRouteUpdate((to, from) => {
    console.log("from", from.params.id)
    console.log("to", to.params.id)
    // console.log(route.params.id)
  })
</script>

<style scoped>
</style>